// Framework7

var myApp = new Framework7();
var $$ = Dom7;
 
var mainView = myApp.addView('.view-main', {
    domCache: true  //内联页面开启 
});

   
var myApp = new Framework7({
    modalButtonOk: "确定",
    modalButtonCancel: "取消",
    animateNavBackIcon: true,
    fastClicks: true,  //300毫秒延迟
    swipePanel: 'left',   
    pushState: true, /*哈希导航*/
    pushStateSeparator: '', /*哈希导航分割 index.html#login*/
    modalTitle: '温馨提示',
    materialRipple:true
});

/*###### 下拉刷新 start ######*/
var songs = ['Yellow Submarine', 'Don\'t Stop Me Now', 'Billie Jean', 'Californication'];
var authors = ['Beatles', 'Queen', 'Michael Jackson', 'Red Hot Chili Peppers'];
// Pull to refresh content
var ptrContent = $$('.pull-to-refresh-content');
// Add 'refresh' listener on it
ptrContent.on('refresh', function (e) {
    // Emulate 2s loading
    setTimeout(function () {
        // 图片数据
        var picURL = 'http://hhhhold.com/88/d/jpg?' + Math.round(Math.random() * 100);
        // Random song
        var song = songs[Math.floor(Math.random() * songs.length)];
        // Random author
        var author = authors[Math.floor(Math.random() * authors.length)];
        // List item html
        var itemHTML = '<li class="listone borderradius boxshadow">'+
                          '<p class="imgbox">'+
                            '<img src="images/imglist/1.jpg">'+
                            '<span class="shareflag"><img src="images/indexshare.png"></span>'+
                          '</p>'+
                          '<p class="word_one">'+
                            '<a class="word_one_left">顾客号：123456789</a>'+
                            '<a class="word_one_right">方案名称</a>'+
                          '</p>'+
                          '<p class="word_two">'+
                            '<a class="word_two_top">风格：现代简约   三室一厅|84㎡</a>'+
                            '<a class="word_two_bottom">2017-08-03  15:23</a>'+
                          '</p>'+
                        '</li>';
        // Prepend new list element
        ptrContent.find('ul.lists').prepend(itemHTML);
        // When loading done, we need to reset it
        myApp.pullToRefreshDone();
    }, 2000);
});
/*###### 下拉刷新 end ######*/
// 登录
// $$('form.ajax-submit-login').on('submitted', function (e) {
//   var xhr = e.detail.xhr; // actual XHR object
 
//   var data = e.detail.data; // Ajax repsonse from action file
//   // do something with response data
// });
// $$('.close-login-screen').on('click', function () {
//   myApp.closeModal($$('.login-screen'));
// });
// $$('.open-login').on('click', function () {
//   myApp.loginScreen();
// });

$$(document).on('pageInit', function (e) {
    var page = e.detail.page;
    if(page.name == 'p-home') {
       var mySwiper = new Swiper('.swiper-container',{
          autoplay:3000,//延迟（毫秒）之间的转换
          speed:500,
          calculateHeight: true,
          pagination: '.pagination',
          paginationClickable: true,
          autoplayDisableOnInteraction : false,
          loop:true
    });

  }
    //新客户
    if(page.name == "p-newclient"){
       $$('.js_greatprogram').on('click', function () {
            myApp.confirm('你确定要创建新方案吗?', function() {
               PAGE_LOAD('#p-createplan'); 
            });
        });

        $$('.js_saveprogram').on('click', function () {
            myApp.confirm('你要保存该顾客吗?', function() {
              PAGE_LOAD('#p-userlist'); 
            });
        });
    }

    // 商城
    if(page.name == "p-shop"){   
         $('#p-shop').shopSelect();
    }
    //商品详情
    if (page.name === 'p-commoditydetails') {
        var mySwiper = new Swiper('.swiper-container',{
          autoplay:3000,//延迟（毫秒）之间的转换
          speed:500,
          calculateHeight: true,
          pagination: '.pagination',
          paginationClickable: true,
          autoplayDisableOnInteraction : false,
          loop:true
        });
    }
    // 选择样式
    if(page.name === 'p-selectstyle') {
      $('#quick_style').on('click',function() {
           PAGE_LOAD('#p-home');
           $('.alert_newprogram').show();
           setTimeout(function () {$('.alert_newprogram').hide();}, 4000);
      });
    }
    //意向商品
    if (page.name === 'p-purpose') {
        //弹框提示   start
        $$('#js_greatprogram').on('click', function () {
            myApp.confirm('你确定要创建新方案吗?', function() {
              PAGE_LOAD('#p-userlist');
            });
        });
        $$('#js_senduser').on('click', function () {
            myApp.confirm('发送到顾客，需要将商品打包压缩生成共享二维码，这可能需要几分钟的时间，确定开始压缩吗？', '温馨提示：');
        });
    }
    // 创建方案
    if (page.name === 'p-createplan') {
       console.log('createplan');  
       $('.js_search_foot').slideDon();
       $('.js_search_top').slideUpt();
       $("#sjld").sjld();
    }  

    if(page.name === 'p-userlist') {
      console.log('p-userlist')
      $('.user_control img').on('click',function() {
         PAGE_LOAD('#p-createplan');
      });
    }
});
//请求外部url加上等待
$$(document).on('ajaxStart', function (e) {
    if (e.detail.xhr.requestUrl.indexOf('autocomplete-languages.json') >= 0) {
        // Don't show preloader for autocomplete demo requests
        return;
    }
    myApp.showIndicator();
});
$$(document).on('ajaxComplete', function (e) {
    if (e.detail.xhr.requestUrl.indexOf('autocomplete-languages.json') >= 0) {
        // Don't show preloader for autocomplete demo requests
        return;
    }
    myApp.hideIndicator();
});

